﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Web;
using SsoaFramework.Service;

namespace DataAccessService
{
    public class DataAccess : DataService<SiteXtenderEntities>
    {
        public static LogService logService = new LogService("DataAccess");

        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperatisonRights.All);
            config.SetEntitySetAccessRule("*",EntitySetRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            

        }

        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            base.OnStartProcessingRequest(args);
            if(!args.RequestUri.AbsolutePath.Contains("Log"))
                logService.Trace("Processing request: "+ args.RequestUri.AbsolutePath);
        }

        protected override void HandleException(HandleExceptionArgs args)
        {
            base.HandleException(args);
        }

        protected override SiteXtenderEntities CreateDataSource()
        {
            return base.CreateDataSource();
        }
    }
}
